home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / MAPEDIT.ZIP / PAINT.C < prev    next >
C/C++ Source or Header  |  1993-05-13  |  12KB  |  466 lines

  1. #include "paint.h"
  2.  
  3. main(int argc, char **argv)
  4. {
  5.     int x=0;
  6.     int y=0;
  7.     char cbuf[128],copybuf[64];
  8.     int oldmouse;
  9.     unsigned int loop;
  10.  
  11.     tbar=160;
  12.     cvis=0;    lcol=1;
  13.     mcol=2;    rcol=100;
  14.     cchar=0;   mapx=0;
  15.     mapy=0;    chy=6;
  16.     mouseon=0;
  17.     current_mode=NORMAL_MODE;
  18.     if(argc<3)
  19.     {
  20.         printf("\nUsage :");
  21.         printf("\n%s characterset.pcx mapname",argv[0]);
  22.         exit(0);
  23.     }
  24.     if(!mousecheck())
  25.     {
  26.         printf("\nThis Program requires a mouse and a mouse driver to run.");
  27.         exit(0);
  28.     }
  29.     if(! (bufptr = (char far *)malloc(64001)))
  30.     {
  31.         printf("\nNot enough free memory. (bufptr)");
  32.         exit(0);
  33.     }
  34.     if(! (mapptr = (int far *)malloc(64001)))
  35.     {
  36.         printf("\nNot enough free memory. (mapptr)");
  37.         exit(0);
  38.     }
  39.     if(! (ca = (struct character_attribute_struct far *)malloc(sizeof(struct character_attribute_struct)*1000 )))
  40.     {
  41.         printf("\nNot enough free memory. (ca - character attribute)");
  42.         exit(0);
  43.     }
  44.     load_db();
  45.     load_map(argv[2]);
  46.     load_charset();
  47.     load_attributes();
  48.     memset(screen,0xff,2000);
  49.     printf("\nLoading Paint program.");
  50.     load_pcx(argv[1],bufptr);
  51.     strcpy(mapname,argv[2]);
  52.     strcpy(charsetname,argv[1]);
  53.     makepal();
  54.     vmode(0x13);
  55.     set_palette();
  56.     show_sprite(0,tbar,"mainmenubar");
  57.     show_map(mapx,mapy,1,tbar/8);
  58.     show_chset(tbar+8,chy);
  59.     mousecursor(1);
  60.     mouseon=1;
  61. //    ask_chset(); not completed yet!!!!
  62.     for(;;)
  63.     {
  64.         mousex=mousecol();
  65.         mousey=mouserow();
  66.         if(mousey<8)
  67.         {
  68.             setrow(8);
  69.             mousey=8;
  70.         }
  71.         update_screen();
  72.         update_sbar();
  73.         if(mouseb=mousebuttons())
  74.         {
  75.             if(mousey<tbar)
  76.                 maphit();
  77.             else if(mousey<tbar+8)
  78.                 barhit();
  79.             else
  80.                 chsethit();
  81.         }
  82.         else
  83.         {
  84.             if(current_mode==DRAW_MODE)
  85.                 current_mode=NORMAL_MODE;
  86.         }
  87.     }
  88. }
  89.  
  90. update_sbar()
  91. {
  92.     char temps[80];
  93.     int loop;
  94.     if(mousey<tbar)
  95.         sprintf(temps,"X:%3d Y:%3d Value: %4d ",mapx+mousex/8,mapy+mousey/8-1,mapptr[mapx+mousex/8+(mapy+mousey/8)*320]);
  96.     else if(mousey>tbar+8)
  97.         sprintf(temps,"X:%3d Y:%3d Value: %4d ",mousex/8,chy+(mousey-tbar)/8-1,mousex/8+((mousey-tbar)/8+chy-1)*40);
  98.     else
  99.         strcpy(temps,"                         ");
  100.     putsline(0,temps);
  101.     if(ca[cchar].block)
  102.     {
  103.         sprintf(temps,"%s %s %s %s",(ca[cchar].block&TOP_BLOCK ? "T":" "),(ca[cchar].block&BOTTOM_BLOCK ? "B":" "),(ca[cchar].block&LEFT_BLOCK ? "L":" "),(ca[cchar].block&RIGHT_BLOCK ? "R":" "));
  104.         putsline(26,temps);
  105.     }
  106.     else
  107.         putsline(26,"       ");
  108.     sprintf(temps,"%3d:",cchar);
  109.     putsline(34,temps);
  110.     pch(38,0,cchar);
  111. }
  112.  
  113. maphit()
  114. {
  115.     static int fromx,fromy;
  116.     int loop;
  117.  
  118.     if(mouseb==2)
  119.     {
  120.         cchar=mapptr[mapx+mousex/8+(mapy+mousey/8)*320];
  121.         current_mode=NORMAL_MODE;
  122.         show_sprite(0,tbar,"mainmenubar");
  123.     }
  124.     else
  125.     {
  126.         memset(screen,0xff,2000);
  127.         switch(current_mode)
  128.         {
  129.         case DRAW_MODE:
  130.             mapline(mapx,mapy,fromx/8,fromy/8,mousex/8,mousey/8,cchar);
  131.         case NORMAL_MODE:
  132.             mapptr[mapx+mousex/8+(mapy+mousey/8)*320]=cchar;
  133.             fromx=mousex;
  134.             fromy=mousey;
  135.             current_mode=DRAW_MODE;
  136.             break;
  137.         case EDIT_MODE:
  138.             edit_pix(mapptr[mapx+mousex/8+(mapy+mousey/8)*320]%40,mapptr[mapx+mousex/8+(mapy+mousey/8)*320]/40);
  139.             for(loop=0;loop<1000;loop++)
  140.                 screen[loop]=0xffff;
  141.             current_mode=NORMAL_MODE;
  142.             show_sprite(0,tbar,"mainmenubar");
  143.             show_map(mapx,mapy,1,tbar/8);
  144.             show_chset(tbar+8,chy);
  145.             show_sprite(0,tbar,"mainmenubar");
  146.             break;
  147.         case COPY_MODE:
  148.             cchar=mapptr[mapx+mousex/8+(mapy+mousey/8)*320];
  149.             current_mode=NORMAL_MODE;
  150.             show_sprite(0,tbar,"mainmenubar");
  151.             break;
  152.         }
  153.     }
  154. }
  155.  
  156. barhit()
  157. {
  158.     int oldmouse;
  159.     if(mousex>48 && mousex<60 )
  160.     {
  161.         show_sprite(50,tbar,"smalldown");
  162.  
  163.         do{
  164.             if(chy<(tbar/8))
  165.             {
  166.                 chy++;
  167.                 vwait();
  168.                 show_chset(tbar+8,chy);
  169.             }
  170.         }   
  171.         while(mousebuttons()==2)
  172.             ;
  173.         while(mousebuttons()==1)
  174.             ;
  175.         show_sprite(0,tbar,"mainmenubar");
  176.     }
  177.     if(mousex>154 && mousex<174)
  178.     {
  179.         show_sprite(155,tbar,"save");
  180.         ask_save();
  181.     }
  182.     if(mousex>134 && mousex<154)
  183.     {
  184.         current_mode=COPY_MODE;
  185.         show_sprite(135,tbar,"copy");
  186.         while(mousebuttons())
  187.             ;
  188.         show_sprite(0,tbar,"pickcopyfrom");
  189.     }
  190.     if(mousex>0 && mousex<0)
  191.     {
  192.         show_sprite(135,tbar,"f");
  193.  
  194.         while(mousebuttons())
  195.             ;
  196.         show_sprite(0,tbar,"mainmenubar");
  197.     }
  198.  
  199.     if(mousex>59 && mousex<69)
  200.     {
  201.         show_sprite(60,tbar,"topin");
  202.         process_block(TOP_BLOCK);
  203.         while(mousebuttons())
  204.             ;
  205.         show_sprite(0,tbar,"mainmenubar");
  206.     }
  207.     if(mousex>69 && mousex<79)
  208.     {
  209.         show_sprite(70,tbar,"bottomin");
  210.         process_block(BOTTOM_BLOCK);
  211.         while(mousebuttons())
  212.             ;
  213.         show_sprite(0,tbar,"mainmenubar");
  214.     }
  215.     if(mousex>79 && mousex<89)
  216.     {
  217.         show_sprite(80,tbar,"leftin");
  218.         process_block(LEFT_BLOCK);
  219.         while(mousebuttons())
  220.             ;
  221.         show_sprite(0,tbar,"mainmenubar");
  222.     }
  223.     if(mousex>89 && mousex<99)
  224.     {
  225.         show_sprite(90,tbar,"rightin");
  226.         process_block(RIGHT_BLOCK);
  227.         while(mousebuttons())
  228.             ;
  229.         show_sprite(0,tbar,"mainmenubar");
  230.     }
  231.     if(mousex>99 && mousex<116)
  232.     {
  233.         show_sprite(100,tbar,"allin");
  234.         process_block(ALL_BLOCK);
  235.         while(mousebuttons())
  236.             ;
  237.         show_sprite(0,tbar,"mainmenubar");
  238.     }
  239.  
  240.  
  241.     if(mousex<9  )
  242.     {
  243.         show_sprite(0,tbar,"smallup");
  244.         do
  245.         {
  246.             if(chy>0)
  247.             {
  248.                 chy--;
  249.                 show_chset(tbar+8,chy);
  250.             }
  251.         } 
  252.         while(mousebuttons()==2);
  253.         while(mousebuttons()==1)
  254.             ;
  255.         show_sprite(0,tbar,"mainmenubar");
  256.     }
  257.     if(mousex>175 && mousex<194)
  258.     {
  259.         show_sprite(175,tbar,"exit");
  260.         while(mousebuttons())
  261.             ;
  262.         show_sprite(0,tbar,"mainmenubar");
  263.         ask_exit();
  264.     }
  265.     if(mousex>119 && mousex< 131)
  266.     {
  267.         mousecursor(0);
  268.         mouseon=0;
  269.         oldmouse=mousey;
  270.         while(mousebuttons()==1)
  271.         {
  272.             mousey=mouserow();
  273.             tbar=mousey & 0xFFF8;
  274.             if(tbar<8)
  275.                 tbar=8;
  276.             memset(screen,0xff,2000);
  277.             vwait();
  278.             show_sprite(0,tbar,"movemainmenu");
  279.             if(mapy>100-tbar/8)
  280.             {
  281.                 mapy=100-tbar/8;
  282.                 show_map(mapx,mapy,1,tbar/8);
  283.             }
  284.             else if(oldmouse<tbar/8)
  285.                 show_map(mapx,mapy,oldmouse,tbar/8);
  286.             if(chy>(tbar/8))
  287.                 chy=tbar/8;
  288.             show_chset(tbar+8,chy);
  289.             oldmouse=tbar/8;
  290.         }
  291.         show_sprite(0,tbar,"mainmenubar");
  292.     }
  293.     if(mousex>294 && mousex<306)
  294.     {
  295.         show_sprite(295,tbar,"bigdown");
  296.         do{
  297.             if(mapy<100-tbar/8)
  298.             {
  299.                 mapy++;
  300.                 show_map(mapx,mapy,1,tbar/8);
  301.             }
  302.         }
  303.         while(mousebuttons()==2);
  304.         while(mousebuttons()==1);
  305.         show_sprite(0,tbar,"mainmenubar");
  306.     }
  307.     if(mousex>282 && mousex<293 )
  308.     {
  309.         show_sprite(282,tbar,"bigup");
  310.         do{
  311.             if(mapy>0)
  312.             {
  313.                 mapy--;
  314.                 show_map(mapx,mapy,1,tbar/8);
  315.             }
  316.         }   
  317.         while(mousebuttons()==2);
  318.         while(mousebuttons()==1)
  319.             ;
  320.         show_sprite(0,tbar,"mainmenubar");
  321.     }
  322.     if(mousex>308 && mousex<320)
  323.     {
  324.         show_sprite(308,tbar,"bigright");
  325.         do{
  326.             if(mapx<320-40)
  327.             {
  328.                 mapx++;
  329.                 show_map(mapx,mapy,1,tbar/8);
  330.             }
  331.         }   
  332.         while(mousebuttons()==2);
  333.         while(mousebuttons()==1)
  334.             ;
  335.         show_sprite(0,tbar,"mainmenubar");
  336.     }
  337.     if(mousex>195 && mousex<216)
  338.     {
  339.         show_sprite(196,tbar,"edit");
  340.         while(mousebuttons())
  341.             ;
  342.         show_sprite(0,tbar,"pickedit");
  343.         current_mode=EDIT_MODE;
  344.     }
  345.     if(mousex>269 && mousex<280)
  346.     {
  347.         show_sprite(269,tbar,"bigleft");
  348.         do{
  349.             if(mapx>0)
  350.             {
  351.                 mapx--;
  352.                 show_map(mapx,mapy,1,tbar/8);
  353.             }
  354.         }   
  355.         while(mousebuttons()==2);
  356.         while(mousebuttons()==1);
  357.         show_sprite(0,tbar,"mainmenubar");
  358.     }
  359. }
  360.  
  361. chsethit()
  362. {
  363.     char temps[128];
  364.     int loop;
  365.  
  366.     switch(current_mode)
  367.     {
  368.     case NORMAL_MODE:
  369.         cchar=mousex/8+((mousey-tbar)/8+chy-1)*40;
  370.         break;
  371.     case EDIT_MODE:
  372.         edit_pix(mousex/8,(mousey-tbar)/8+chy-1);
  373.         for(loop=0;loop<1000;loop++)
  374.             screen[loop]=0xffff;
  375.         show_sprite(0,tbar,"mainmenubar");
  376.         show_map(mapx,mapy,1,tbar/8);
  377.         show_chset(tbar+8,chy);
  378.         current_mode=NORMAL_MODE;
  379.         break;
  380.     case DEST_MODE:
  381.         btc(cchar%40,cchar/40,temps);
  382.         ctb(mousex/8,(mousey-tbar)/8+chy-1,temps);
  383.         while(mousebuttons());
  384.         show_sprite(0,tbar,"mainmenubar");
  385.         current_mode=NORMAL_MODE;
  386.         break;
  387.     case COPY_MODE:
  388.         cchar=mousex/8+((mousey-tbar)/8+chy-1)*40;
  389.         show_sprite(0,tbar,"pickpasteto");
  390.         while(mousebuttons());
  391.         current_mode=DEST_MODE;
  392.         break;
  393.     }
  394. }
  395.  
  396. update_screen()
  397. {
  398.     if(mousey<tbar)
  399.     {
  400.         if(mouseon)
  401.         {
  402.             mousecursor(0);
  403.             mouseon=0;
  404.         }
  405.         vwait();
  406.         cross(mousex,mousey,8,tbar);
  407.         vwait();
  408.         block(mousex/8,mousey/8,0);
  409.         vwait();
  410.         block(mousex/8,mousey/8,1);
  411.         vwait();
  412.         cross(mousex,mousey,8,tbar);
  413.         pch(mousex/8,mousey/8,mapptr[mapx+mousex/8+(mapy+mousey/8)*320]);
  414.     }
  415.     else if(mousey<tbar+8 )
  416.     {
  417.         if(!mouseon)
  418.         {
  419.             mousecursor(1);
  420.             mouseon=1;
  421.             waitup();
  422.         }
  423.     }
  424.     else
  425.     {
  426.         if(mouseon)
  427.         {
  428.             mousecursor(0);
  429.             mouseon=0;
  430.         }
  431.         vwait();
  432.         block(mousex/8,mousey/8,0);
  433.         vwait();
  434.         block(mousex/8,mousey/8,1);
  435.         vwait();
  436.         pch(mousex/8,mousey/8,mousex/8+((mousey-tbar)/8+chy-1)*40);
  437.     }
  438. }
  439.  
  440. process_block(int blocks)
  441. {
  442.  
  443.     switch(blocks)
  444.     {
  445.         case TOP_BLOCK:
  446.             ca[cchar].block ^=TOP_BLOCK;
  447.             break;
  448.         case BOTTOM_BLOCK:
  449.             ca[cchar].block ^=BOTTOM_BLOCK;
  450.             break;
  451.         case LEFT_BLOCK:
  452.             ca[cchar].block^=LEFT_BLOCK;
  453.             break;
  454.         case RIGHT_BLOCK:
  455.             ca[cchar].block ^=RIGHT_BLOCK;
  456.             break;
  457.         case ALL_BLOCK:
  458.             if(ca[cchar].block==ALL_BLOCK)
  459.                 ca[cchar].block=0;
  460.             else
  461.                 ca[cchar].block=ALL_BLOCK;
  462.  
  463.     }
  464. }
  465.  
  466.